import service from "@/utils/request.js";
import qs from 'qs';

const cartApi = {
	add(productId) {
		return service.post(`/order/cart/add/${productId}`);
	},
	deleteById(id) {
		return service.delete(`/order/cart/deleteById/${id}`);
	},
	deleteByIds(ids) {
		return service.delete("/order/cart/deleteByIds", {
			data: {
				ids
			}
		});
	},
	update(cart) {
		return service.put("/order/cart/update", cart);
	},
	list() {
		return service.get("/order/cart/list");
	},
	selectById(id) {
		return service.get(`/order/cart/${id}`);
	},
	selectByIds(cartIds) {
		// /cart/selectByIds?cartIds=1&cartIds=2&cartIds=3
		let params = "?cartIds=";
		for (let i = 0; i < cartIds.length; i++) {
			params += cartIds[i];
			if(i != cartIds.length - 1) {
				params += '&cartIds='
			}
		}

		return service.get(`/order/cart/selectByIds${params}`);
	}
};


export default cartApi;